float3 fvLightPosition;
float3 fvEyePosition;
float4x4 matView;
float4x4 matViewProjection;

struct VS_INPUT 
{
   float4 Position : POSITION0;
   float2 Texcoord : TEXCOORD0;
   float3 Normal :   NORMAL0;
   
};

struct VS_OUTPUT 
{
   float4 Position :        POSITION0;
   float2 Texcoord :        TEXCOORD0;
   float3 ViewDirection :   TEXCOORD1;
   float3 LightDirection :  TEXCOORD2;
   float3 Normal :          TEXCOORD3;
   
};

VS_OUTPUT vs_main( VS_INPUT Input )
{
   VS_OUTPUT Output;

   Output.Position         = mul( Input.Position, matViewProjection );
   Output.Texcoord         = Input.Texcoord;
   
   float3 fvObjectPosition = mul( Input.Position, matView );
   
   Output.ViewDirection    = fvEyePosition - fvObjectPosition;
   Output.LightDirection   = fvLightPosition - fvObjectPosition;
   Output.Normal           = mul( Input.Normal, matView );
      
   return( Output );
   
}


struct PS_INPUT 
{
   float3 LightDirection:   TEXCOORD2;
   float3 Normal :          TEXCOORD3;
   
};

float4 ps_main( PS_INPUT Input ) : COLOR0
{
   int i = 0;
   float temp = 0.0f;      
   float3 normale = normalize(Input.Normal);
   float3 lightDirection = normalize(Input.LightDirection);
   float4 ret = 0.0f;
   
   for (i = 0; i < 3; i++)
   {
      temp += normale[i] * lightDirection[i];
   }
   
   if (temp > 0.7)
      return 0.2;
   else if( temp > 0.4)
   {
      ret[0] = 0.3f;
      ret[1] = 0.6f;
      ret[2] = 0.1f;
      return ret; 
   }
   else if (temp > 0.001f)
	return 0.5f;
   else
      return 1; 
}


float4 ps_main2( PS_INPUT Input ) : COLOR0
{
   int i = 0;
   float temp = 0.0f;      
   float3 normale = normalize(Input.Normal);
   float3 lightDirection = normalize(Input.LightDirection);
   float4 ret = 0.0f;
   
   for (i = 0; i < 3; i++)
   {
      temp += normale[i] * lightDirection[i];
   }
   
   if (temp > 0.7)
      return 0.2;
   else if( temp > 0.4)
   {
      ret[0] = 0.1f;
      ret[1] = 0.3f;
      ret[2] = 0.6f;
      return ret; 
   }
   else if (temp > 0.001f)
	return 1;
   else
      return 0.1f; 
}

technique Cartoon_Shader
{
	pass Pass2
   {
		VertexShader = compile vs_2_0 vs_main();
		PixelShader = compile ps_2_0 ps_main2();
   }
   pass Pass1
   {
	  VertexShader = compile vs_2_0 vs_main();
      PixelShader = compile ps_2_0 ps_main();
   }
   
} 